package com.example.leetdemo.finash;

import java.util.*;

public class Solution49 {

    public List<List<String>> groupAnagrams(String[] strs) {
        Map<String, List<String>> map = new HashMap<>();
        for(int i = 0; i < strs.length; i++) {
            char[] charArr = strs[i].toCharArray();
            Arrays.sort(charArr);
            String tt = String.copyValueOf(charArr);
            List<String> list = map.getOrDefault(tt, new ArrayList<>());
            list.add(strs[i]);
            map.put(tt, list);
        }
        List<List<String>> result = new ArrayList<>();
        for (String key : map.keySet()) {
            result.add(map.get(key));
        }
        return result;
    }

}
